{% extends "base.html" %}

{% block content %}
<!--热门电影-->

<!--热门电影-->
<!--电影列表-->
<section id="movielist">
    <div class="container2">
        <input type="text" class="playlist" value="[]" hidden>
        <div class="row wow fadeIn box videolist" data-wow-delay="0.6s" style="position: relative;width: 100%;">
            <div class="col-md-12 table-responsive"></div>
        </div>
    </div>
</section>

{% end %}

{% block js %}
<script>
    function getArea(){
        var area = localStorage['area'];
        if (typeof(area)=='undefined'){
            localStorage.setItem('area',1);
            area = 1
        }
        return area
    }
    function selectAuthor(obj){ // 选中演员
        var _this = $(obj);
        var name = _this.attr('name');
        if(Author==name){
            Author = null;
            name='';
        }else{
            Author = name;
        }
        $('.showpop').css('display','none');
        getvideos(area=Area,author=name);
    }
    function getAuthors(author=''){ // 获取演员列表
        $('.author-list').html('');
        var query = '?name='+author;
        $.get('/author'+query,function (res){
            res = JSON.parse(res);
            if(res.code==0){
                var authors = res.data.list;
                for(var i in authors){
                    var author = authors[i];
                    var name = author.author;
                    if(name==''){name='无'}
                    if(name==Author){
                        var div = '<div class="author-btn selected" onclick="selectAuthor(this)" name="'+name+'">'+author.author+'('+author.num+')</div>';
                    }else{
                        var div = '<div class="author-btn" onclick="selectAuthor(this)" name="'+name+'">'+author.author+'('+author.num+')</div>';
                    }
                    $('.author-list').append(div);
                }
            }else {
                alert(res.msg);
            }
        })
    }
    //初始化
    window.onload = function(){
        Area = getArea();
        $('.sort-list').css('display','flex');
        $('.sort-list .sort-btn').click(function (){
            var id = $(this).attr('id');
            var value = $(this).attr('value');
            if(id=='sort-area'){
                value = Number(value)+1;
                if(value>=3){value=0}
                getvideos(area=value);
            }else if(id=='sort-author'){
                var showPop = $('.showpop');
                if(showPop.is(":hidden")){
                    showPop.css('display','flex');
                    getAuthors();
                }
            }
        });
        $('#close').click(function (){
            $('.showpop').css('display','none');
        });
        getvideos(area=Area)
    }
</script>
<script type="text/javascript">
    
</script>
<!--电影列表-->
{% end %}